# -*- coding: utf-8 -*-
from PyQt5.QtCore import QAbstractTableModel, Qt
from PyQt5.QtWidgets import *

class DataModel(QAbstractTableModel):
    def __init__(self, data, header):
        super(DataModel, self).__init__()

        if data is not None:
            self.row_count = len(data)
            self.col_count = len(data[0])
        else:
            self.row_count = 0
            self.col_count = 0

        self.data = data
        self.header = header

    def rowCount(self, QModelIndex_parent=None, *args, **kwargs):
        return self.row_count

    def columnCount(self, QModelIndex_parent=None, *args, **kwargs):
        return self.col_count

    def headerData(self, p_int, Qt_Orientation, int_role=None):
        if int_role == Qt.DisplayRole and Qt_Orientation == Qt.Horizontal:
            if self.header is None:
                return ""
            return self.header[p_int][0]
        else:
            return None

    def data(self, QModelIndex, int_role=None):
        if int_role == Qt.DisplayRole:
            try:
                if self.data is None:
                    return ""
                return self.data[QModelIndex.row()][QModelIndex.column()]
            except:
                return None
        else:
            return None
